<?php

namespace App\Services;

use App\Models\KeywordSearch;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Model;

class KeywordSearchService
{
    /**
     * Get keyword search list
     * @param int $per_page
     * @return LengthAwarePaginator
     */
    public static function getList(int $per_page): LengthAwarePaginator
    {
        return KeywordSearch::query()
            ->orderBy('id', 'desc')
            ->paginate($per_page);
    }

    /**
     * Store Keyword Search
     * @param array $params
     * @return KeywordSearch|Model
     */
    public static function storeKeywordSearch(array $params): Model|KeywordSearch
    {
        return KeywordSearch::query()->create($params);
    }

    /**
     * Get Keyword Search
     * @param string $map
     * @param string $category
     * @param string $province
     * @param string $city
     * @param string $district
     * @param string $keyword
     * @return KeywordSearch|null
     */
    public static function getKeywordSearch(string $map, string $category, string $province, string $city, string $district, string $keyword): ?KeywordSearch
    {
        return KeywordSearch::query()
            ->where('map', $map)
            ->where('category', $category)
            ->where('province', $province)
            ->where('city', $city)
            ->where('district', $district)
            ->where('keyword', $keyword)
            ->first();
    }

    public static function getKeywordSearch1(string $map, string $category, string $province, string $city, string $district, string $address, int $radius, string $keyword): ?KeywordSearch
    {
        return KeywordSearch::query()
            ->where('map', $map)
            ->where('category', $category)
            ->where('province', $province)
            ->where('city', $city)
            ->where('district', $district)
            ->where('address', $address)
            ->where('radius', $radius)
            ->where('keyword', $keyword)
            ->first();
    }
}
